package pers.qianyu.module.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import pers.qianyu.module.core.domain.system.entity.SysResourcePO;
import pers.qianyu.module.core.domain.system.entity.SysRolePO;
import pers.qianyu.module.core.domain.system.entity.SysRoleResourcePO;

import java.util.List;

/**
 * @author mizzle rain
 * @date 2021-05-03 22:42
 */
@Mapper
public interface SysRoleResourceDao extends BaseMapper<SysRoleResourcePO> {
    @Select("select sr.signature, sr.remark, sr.uri, sr.method, sr.serv, sr.status, sr.id,\n" +
            "       sr.create_time, sr.update_time, sr.created_by, sr.updated_by\n" +
            "from sys_role_resource srr\n" +
            "left join sys_resource sr\n" +
            "on sr.id = srr.resource_id\n" +
            "where sr.deleted = 0\n" +
            "and srr.deleted = 0\n" +
            "and srr.role_id = #{roleId};")
    List<SysResourcePO> selectResourcesByRoleId(@Param("roleId") Long roleId);

    @Select("select sr.role_name, sr.role_key, sr.status, sr.id, sr.create_time,\n" +
            "       sr.update_time, sr.created_by, sr.updated_by\n" +
            "from sys_role_resource srr\n" +
            "left join sys_role sr\n" +
            "on sr.id = srr.role_id\n" +
            "where sr.deleted = 0\n" +
            "and srr.deleted = 0\n" +
            "and srr.resource_id = #{resourceId};")
    List<SysRolePO> selectRoleByResourceId(@Param("resourceId") Long resourceId);
}
